package com.qf.ssm.controller;

import com.qf.ssm.common.vo.ResponseResult;
import com.qf.ssm.entity.Evaluate;
import com.qf.ssm.entity.Store;
import com.qf.ssm.entity.Type;
import com.qf.ssm.service.StoreAppService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 86155
 * @ClassName: com.qf.ssm.controller.StoreController
 * @Description: 该类的功能描述
 * @date: 2021/10/11 19:55
 */
@RestController
@RequestMapping("/store/app")
public class StoreAppController {
    @Resource
    private StoreAppService storeAppService;

    /**
     * 首页根据商店类型tid 查询对应类型的所有商店
     *
     * @param tid 这个参数要写在路径上
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/find/tid/{tid}")
    public ResponseResult<List<Store>> findStoreByTid(@PathVariable("tid") Long tid,
                                                      @RequestParam(defaultValue = "1") Integer page,
                                                      @RequestParam(defaultValue = "10") Integer size) {
        List<Store> stores = storeAppService.findStoreByTid(tid, page, size);
        return ResponseResult.success(stores);
    }

    /**
     * 首页查找所有的商店经营类型
     *
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/type")
    public ResponseResult<List<Type>> findAllType(@RequestParam(defaultValue = "1") Integer page,
                                                  @RequestParam(defaultValue = "10") Integer size) {
        List<Type> types = storeAppService.findAllType(page, size);
        return ResponseResult.success(types);
    }

    /**
     * 首页用户点击首页分类的店铺后进入店铺
     * @param sid  这个参数要写在路径上
     * @return
     */
    @GetMapping("/find/sid/{sid}")
    public ResponseResult<Store> findStoreBySid(@PathVariable("sid") Long sid) {
        Store store = storeAppService.findStoreBySid(sid);
        return ResponseResult.success(store);
    }

    /**
     * 首页根据店铺名称或者商品名称进行查询
     *
     * @param searchName 店铺名称或者商品名称
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/search")
    public ResponseResult<List<?>> searchStoreOrProduct(@RequestParam("searchName") String searchName,
                                                        @RequestParam(defaultValue = "1") Integer page,
                                                        @RequestParam(defaultValue = "10") Integer size) {
        List<?> list = storeAppService.searchStoreOrProduct(searchName, page, size);
        return ResponseResult.success(list);
    }

    /**
     * 查看店铺的所有评价内容
     *
     * @param storeId
     * @return
     */
    @GetMapping("/evaluate")
    public ResponseResult<List<Evaluate>> findEvaluate(@RequestParam Long storeId) {
        List<Evaluate> evaluateList = storeAppService.findEvaluate(storeId);
        return ResponseResult.success(evaluateList);
    }



}
